package com.lsw.dialog;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.lsw.Base.BaseHolder;
import com.lsw.Base.BaseSimpleAdapter;
import com.lsw.R;

/**
 * Created by Administrator on 2018/7/27 0027.
 */

public class DialogListViewAdapter extends BaseSimpleAdapter<String> {
    public DialogListViewAdapter(Context context) {
        super(context);
    }

    public int seclect = 0;

    public int getSeclect() {
        return seclect;
    }

    @Override
    protected BaseHolder<String> getHolder() {
        return new BaseHolder<String>() {
            CheckBox checkBox;
            TextView tv_title;

            @Override
            public void bindViews(View parentView) {
                checkBox = parentView.findViewById(R.id.checkBox);
                tv_title = parentView.findViewById(R.id.tv_title);
            }

            @Override
            public void bindData(String item, final int position) {
                if (seclect == position) {
                    checkBox.setChecked(true);
                } else {
                    checkBox.setChecked(false);
                }
                tv_title.setText(item);
                tv_title.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        checkBox.setChecked(!checkBox.isChecked());
                    }
                });
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            seclect = position;
                            notifyDataSetChanged();
                        }
                    }
                });
            }
        };
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.item_dialog_listview;
    }
}
